mui.init();

mui.plusReady(function () {
	
	var username = document.getElementById('username');    
	var password = document.getElementById('password');
	var register = document.getElementById('register');
	
	register.addEventListener('tap',function(){
		if(username.value.length == 0){
			plus.ui.toast('用户名不能为空');
			return false;
		}
		if(password.value.length == 0){
			plus.ui.toast('密码不能为空');
			return false;
		}
		
		var api_host = plus.storage.getItem('HOST_URL');
		var synlogininfo=plus.storage.getItem('synlogininfo');
		var synlogintype=plus.storage.getItem('synlogintype');
		var ws = plus.webview.currentWebview();
		mui.ajax({
			url:api_host+'/api/linxuan/user/existaccount',
			data:{'username':username.value,'password':password.value,'synlogininfo':synlogininfo,'synlogintype':synlogintype},
			dataType:'json',//服务器返回json格式数据
			type:'post',//HTTP请求类型
			headers:{'User-Token':plus.storage.getItem('UserToken')},
			timeout:3000,//超时时间设置为3秒；
			success:function(data){
				if(data.code==1){
					plus.storage.setItem('UserToken', data.data);
					mui.toast(data.msg,{ duration:'2000', type:'div'});
					plus.webview.getWebviewById('bindExAccount').close();
					plus.webview.getWebviewById('loginHtml').close();
					plus.webview.getWebviewById('bindAccount').close();
					plus.webview.close(ws);
				}else{
					mui.toast(data.msg);
				}
			},
			error:function(xhr,type,errorThrown){
				mui.toast("请求失败，请检查网络！");
			}
		});
	});
});